package com.lib.listener;

import com.lib.dto.RentalAgentApplyDTO;
import com.lib.listener.event.RentalAgentApplyEvent;
import com.lib.service.WxAgentService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * Created by duqingxiang on 17/5/24.
 */
@Component
public class RentalAgentApplyListener {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    WxAgentService wxAgentService;

    @EventListener
    public void sendApplayMessage(RentalAgentApplyEvent event) {

        try {
            WxMpTemplateMessage msg = WxMpTemplateMessage.builder()
                    .toUser(event.getOpenId())
                    .url(event.getTemplateUrl())
                    .templateId(RentalAgentApplyEvent.TEMPLATE_ID)
                    .build();

            wxAgentService.getTemplateMsgService().sendTemplateMsg(msg) ;

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
